package com.jevoly.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import java.io.IOException;

/**
 * 项目启动后自动打开显示端
 */
@Configuration
public class IndexConfig {

    private static Log log = LogFactory.getLog(IndexConfig.class);

    @Value("${server.port}")
    String port;

    @EventListener({ApplicationReadyEvent.class})
    void applicationReadyEvent() {
        log.info("正在启动浏览器...");
        String url = "http://localhost:" + port;
        try {
            Runtime.getRuntime().exec(new String[]{"cmd", "/c", "start chrome.exe --kiosk " + url});
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 